class ChartTagLib {
	def burnDownCSChart ={attrs ->
		if(!attrs.yMaxValue || !attrs.xMaxValue || !attrs.fullSprintX || !attrs.fullSprintY || !attrs.dataExpected || !attrs.dataBurned){
			out<<"NO DATA FOR CHART"
			return
		}
		def yMaxValue=attrs.yMaxValue
		def xMaxValue=attrs.xMaxValue
		def fullSprintX = attrs.fullSprintX
		def fullSprintY=attrs.fullSprintY
		def yMaxValueInTwenty = yMaxValue/20
		def defSprintY=fullSprintY.findAll{it%(Integer)yMaxValueInTwenty==0}
		def dataExpected=attrs.dataExpected
		def dataBurned=attrs.dataBurned
		def chxl=getChxl(fullSprintX,defSprintY)
		def dataExpectedCSV=dataExpected.join(",")
		def dataBurnedScaleDaysCSV=(0..dataBurned.size()).join(",")
		def dataBurnedCSV=dataBurned.join(",")
		out << """ 
 		<img src=\'http://chart.apis.google.com/chart?chs=700x400&chxt=x,y&chco=FF0000,0000FF&chdl=Quemada|Esperada&chtt=BurnDown%20Chart&cht=lxy
			&chds=0,${xMaxValue+1},0,$yMaxValue&chxl=$chxl&chd=t:$dataBurnedScaleDaysCSV|$dataBurnedCSV|-1|$dataExpectedCSV\'>
	   """
		
	}
	def getChxl(fullSprintX,fullSprintY){
		def chxl=""
		chxl+="0:|"
		fullSprintX.each{
			chxl+="$it|"
		}
		chxl+="1:|"
		fullSprintY.each{
			chxl+="$it|"
		}
		return chxl
	}
}
